package com.boot.datademo2.service.impl;

import com.boot.datademo2.controller.model.UserRegisterRequest;
import com.boot.datademo2.dao.mapper.UserMapper;
import com.boot.datademo2.dao.pojo.UserDO;
import com.boot.datademo2.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * registerservice的实现类，调用mapper接口，去验证用户名是否已存在
 **/
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int getRegisterStatus(UserRegisterRequest userRegisterRequest) {
        int status;
        UserDO userByName = userMapper.getUserByName(userRegisterRequest.getName());

        UserDO user = new UserDO();
        user.setId(userRegisterRequest.getId());
        user.setName(userRegisterRequest.getName());
        user.setPwd(userRegisterRequest.getPwd());

        if (userByName==null){
            userMapper.addUser(user);
            status = 0;
        }else {
            status = 1;
        }
        return status;
    }
}
